package osx.mantianx.read;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author starrysky
 * @title: PoiReadV07
 * @projectName Excel_Poi_EasyExcel
 * @description: TODO
 * @date 2021/2/410:30
 */
public class PoiReadV07 {
    public static void main(String[] args) {
        FileInputStream stream =null;
        XSSFWorkbook workbook =null;
        try {
            stream = new FileInputStream("XlsBigTablesV07First.xlsx");
            if (stream!=null){
                workbook = new XSSFWorkbook(stream);

                Sheet sheetAt = workbook.getSheetAt(0);

                for (int rowNumber = 0; rowNumber < 65536; rowNumber++) {
                    StringBuilder stringBuilder = new StringBuilder();
                    Row row = sheetAt.getRow(rowNumber);
                    if (rowNumber!=0){

                        for (int colNumber = 0; colNumber < 6; colNumber++) {
                            stringBuilder.append("| ");
                            stringBuilder.append(row.getCell(colNumber).getNumericCellValue());
                            stringBuilder.append(" |");
                        }
                    }else {
                        for (int colNumber = 0; colNumber < 6; colNumber++) {
                            stringBuilder.append("| ");
                            stringBuilder.append(row.getCell(colNumber).getStringCellValue());
                            stringBuilder.append(" |");
                        }
                    }
                    System.out.println(stringBuilder.toString());
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (stream!=null){
                try {
                    stream.close();
                    if (workbook!=null){
                        workbook.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
